package com.hxy.subscribe;

import redis.clients.jedis.JedisPubSub;

/**
 * 订阅者
 */
public class Subscriber extends JedisPubSub {

    public Subscriber() {
    }

    /**
     * 收到消息会调用
     *
     * @param channel
     * @param message
     */
    @Override
    public void onMessage(String channel, String message) {
        System.out.println(String.format("收到Redis发布的消息, 频道名：%s, 消息内容：%s", channel, message));
    }

    /**
     * 订阅了频道会调用
     *
     * @param channel
     * @param subscribedChannels
     */
    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
        System.out.println(String.format("订阅Redis频道成功！ 频道：%s, 订阅频道：%d", channel, subscribedChannels));
    }

    /**
     * 取消订阅 会调用
     *
     * @param channel
     * @param subscribedChannels
     */
    @Override
    public void onUnsubscribe(String channel, int subscribedChannels) {
        System.out.println(String.format("取消Redis频道订阅, 频道名：%s, 订阅频道：%d", channel, subscribedChannels));
    }
}
